package com.nd.android.u.ui.widge;

import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.media.AudioManager;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.nd.android.u.ui.R;

/**
 * ClassName:PopAudioModeNotice
 * Function: 语音播放模式弹窗提醒
 * Reason:	 
 * @author   cb		
 * @version  Ver 1.3.3_modularization
 * @Date	 2014	2014-3-14		下午7:34:19
 *
 * @see 	 
 */
public class PopAudioModeNotice {
	private Context mContext;
	private PopupWindow mWindow;
	private TextView tvNote;
	private View mAnchor;
	public PopAudioModeNotice(Context context,View anchor){
		mContext=context;
		mAnchor=anchor;
		initView();
	}
	
	@SuppressWarnings("deprecation")
	private void initView(){
		View view=LayoutInflater.from(mContext).inflate(R.layout.audio_notice, null);
		mWindow=new PopupWindow(view,-1,-2);
		mWindow.setBackgroundDrawable(new BitmapDrawable());
		mWindow.setFocusable(true);
		mWindow.setOutsideTouchable(true);
		tvNote=(TextView)view.findViewById(R.id.tvNote);
		view.findViewById(R.id.tvClose).setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				if (mWindow!=null){
					mWindow.dismiss();
				}
			}
		});
	}
	
	/**
	 * @n<b>函数名称</b>     :setMode
	 * @brief 设置播放模式
	 * @version    Ver 1.3.3_modularization
	 * @param  @param mode
	 * @return void
	 * @<b>作者</b>          :  cb
	 * @<b>创建时间</b>      :  2014-3-14下午7:35:07      
	*/
	public void setMode(int mode){
		if (mode==AudioManager.MODE_IN_CALL){
			tvNote.setText(R.string.chat_audio_phone);
		}else{
			tvNote.setText(R.string.chat_audio_loud);
		}
	}
	
	/**
	 * @n<b>函数名称</b>     :show
	 * @brief 显示弹窗
	 * @version    Ver 1.3.3_modularization
	 * @param  
	 * @return void
	 * @<b>作者</b>          :  cb
	 * @<b>创建时间</b>      :  2014-3-14下午7:35:14      
	*/
	public void show(){
		if (mWindow==null){
			initView();
		}
		try {
			mWindow.showAsDropDown(mAnchor);
//			mWindow.showAtLocation(((Activity)mContext).getWindow().getDecorView(), Gravity.CENTER, 0, 0);
			new Handler().postDelayed(new Runnable() {
				public void run() {
					try {
						mWindow.dismiss();						
					} catch (Exception e) {
					}
				}
			}, 3000);
		} catch (Exception e) {
		}
	}
}
